{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}

<div class="p-3">
	<form class="layui-form gg-form-bar border-t border-x">
		<div class="layui-input-inline">
			<select name="grade">
				<option value="3B">三年级下册</option>
				<option value="4B">四年级下册</option>
				<option value="5B">五年级下册</option>
				<option value="6B">六年级下册</option>
				<option value="7B">电脑编程下册</option>
				
				<option value="3A">三年级上册</option>
				<option value="4A">四年级上册</option>
				<option value="5A">五年级上册</option>
				<option value="6A">六年级上册</option>
				<option value="7A">电脑编程上册</option>
				
			</select>
		</div>
		<div class="layui-input-inline" style="width:300px;">
			<input type="text" name="keywords" placeholder="请输入关键字" class="layui-input" autocomplete="off" />
		</div>
		<div class="layui-input-inline">
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="searchform">提交搜索</button>
		</div>
	</form>
	<table class="layui-hide" id="course_xinxikeji" lay-filter="course_xinxikeji"></table>
	
</div>
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<span class="layui-btn layui-btn-sm add-menu" lay-event="add" data-title="添加课程类别">+ 添加课程类别</span>
	</div>
</script>

<script type="text/html" id="barDemo">
<span class="layui-btn-group"><a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="read">查看</a><a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a><a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a></span>
</script>


{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool'];
	function gouguInit() {
		var table = layui.table, treeTable = layui.treeTable, tool = layui.tool, form = layui.form;
		layui.pageTable = treeTable.render({

		    // id:'course_xinxikeji',		    
			elem: '#course_xinxikeji',
			//treeColIndex:5,	//树形图标显示在第几列			
			url: '/admin/course_xinxikeji/datalist'
			,treeSpid: '0' //最上级的父级id
			, treeId: 'id'  //树形id字段名称
			, treeUpId: 'pid'//树形父id字段名称
			,treeDefaultClose: true	//是否默认折叠
            ,treeLinkage: false		//父级展开时是否自动展开所有子级
			, height: 'full+60'//满屏-10,即预留底边10			
			, toolbar: '#toolbarDemo'	
			, page: true,			
			limit: 120,
			cellMinWidth: 30,
			tree: {
				customName: {
		         name: 'title',
		         pid: 'pid',
		       },
		      view: {
		      	showIcon:true		        
		      },
		      data: {
		        // isSimpleData: true
		      }
		      /*
		      // 异步加载子节点
		      async: {
		        enable: true,
		        url: '/static/json/2/treeTable/demo-async.json', // 此处为静态模拟数据，实际使用时需换成真实接口
		        autoParam: ["parentId=id"]
		      }
		      */
		    },
			cols: [
				[
				{type: 'checkbox', fixed: 'left'
			    },{
					fixed: 'left',
					field: 'id',
					title: '编号',
					align: 'center',
					width: 80
				},{
					field: 'grade',
					title: '年级A',
					sort: true,
					align: 'center',
					width: 100
				},{
					field: 'pid',
					title: '上一分级',
					align: 'center',
					width: 100
				},{
					field: 'grade_t',
					title: '年级标题',
					sort: true,
					align: 'center',
					width: 100
				},{
					field: 'title',
					title: '课程标题',
				},{
					field: 'allow_ext',
					title: '上传扩展名',
					align: 'center',
					width: 100
				},{
					field: 'update_time',
					title: '更新时间',
					align: 'center',
					width: 100
				},{
					field: 'create_time',
					title: '创建时间',
					align: 'center',
					width: 100
				},{
					field: 'sort',
					title: '排序',
					align: 'center',
					width: 100
				},{
					field: 'uid',
					title: '用户id',
					align: 'center',
					width: 100
				},{
					field: 'status',
					title: '状态',
					align: 'center',
					width: 100
				},
				{
					fixed: 'right',					
					title: '操作',
					toolbar: '#barDemo',
					width: 136,
					align: 'center',

				}				
				]
			]
		});
		
		//监听表头工具栏事件
			treeTable.on('toolbar(course_xinxikeji)', function(obj){
			if (obj.event === 'add') {
				tool.side("/admin/course_xinxikeji/add");
				return false;
			}
		});

		//监听表格行工具事件
		treeTable.on('tool(course_xinxikeji)', function(obj) {
			var data = obj.data;
			if (obj.event === 'read') {
				tool.side('/admin/course_xinxikeji/read?id='+obj.data.id);
			}
			else if (obj.event === 'edit') {
				tool.side('/admin/course_xinxikeji/edit?id='+obj.data.id);
			}
			else if (obj.event === 'del') {
				layer.confirm('确定要删除该记录吗?', {
					icon: 3,
					title: '提示'
				}, function(index) {
					let callback = function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							obj.del();
						}
					}
					tool.delete("/admin/course_xinxikeji/del", { id: data.id }, callback);
					layer.close(index);
				});
			}
			return false;
		});

		//监听搜索提交
		form.on('submit(searchform)', function(data) {
			layui.pageTable.reload({
				where: {
					keywords: data.field.keywords,
					grade:data.field.grade,
				},
				page: {
					curr: 1
				}
			});
			return false;
		});
	}
</script>
{/block}
<!-- /脚本 -->